from langchain_community.utilities import SQLDatabase

#连接sqlite数据库
# db = SQLDatabase.from_uri("sqlite:///demo.db")
#连接MySQL数据库
db_user  = "root"
db_password = "123456"
db_host = "127.O.O.1"
db_port = "3306"
db_name = "llm"
db = SQLDatabase.from_uri(f"mysql+pymysql://{db_user}:{db_password}@{db_host}:{db_port}/{db_name}")

print("那种数据库：", db.dialect)
print("获取数据库：", db.get_usable_table_names())
#执行查询
res = db.run("SELECT count* FROM students;")
print("查询结果：",res)